#!/bin/bash
# ********************************************
# * 作者：			haiqiu
# * 脚本功能：	配置阿里镜像源
# * 脚本时间：	2025-09-19:17-23-12
# * 联系：			2477116273@qq.com
# ********************************************

backup_profile.d() {
  if [ ! -e /etc/yum.repos.d/backup  ]
  then
    mkdir -p /etc/yum.repos.d/backup
  fi
  
  mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup 2>/dev/null || true
  echo "旧文件已备份至/etc/yum.repos.d/backup目录中"
}

set_mirrors() {
  
  if [[ "${linux_version}" =~ ^Rocky.*9 ]] 
  then
    sed -e 's|^mirrorlist=|#mirrorlist=|g' \
    -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
    -i.bak \
    /etc/yum.repos.d/rocky*.repo
    yum makecache
    echo "rocky9 镜像源配置完成~"
  elif [[ "${linux_version}" =~ ^CentOS.*7 ]]
  then
    backup_profile.d
    wget -O /etc/yum.repos.d/CentOS-AliBase.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    yum makecache
  fi
}

set_mirrors
